package com.zzc.emotisenseclassroom.dao.user;

import com.zzc.baseRepository.componet.impl.TableFile;
import com.zzc.baseRepository.componet.interfaces.BaseDao;
import com.zzc.baseRepository.componet.interfaces.ITableFile;
import com.zzc.emotisenseclassroom.pojo.UserLogin;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.Arrays;
import java.util.List;

/**
 * Copyright Zzc
 * FileName: UserDao
 * Author:   Zzc
 * Date:     2024/4/1713:11
 * Description:用户dao层
 * hISTORY:
 * <author>  <time>     <version>    <desc>
 * 作者姓名   修改时间       版本号       描述
 * Zzc                   1.0.0
 */
@Repository
@Mapper
public interface UserDao extends BaseDao {
    /**
     * 用户账号,作为主键
     */
    TableFile ACCOUNT_NUMBER = new TableFile("account_number", "accountNumber", "用户账号,作为主键", JdbcType.BIGINT, Long.class, UserDao.class);

    /**
     * 用户密码
     */
    TableFile PASSWORD = new TableFile("password", "passWord", "用户密码", JdbcType.VARCHAR, String.class, UserDao.class);

    /**
     * 用户类型0-teacher 1-student
     */
    TableFile USER_TYPE = new TableFile("user_type", "userType", "用户类型0-teacher 1-student", JdbcType.TINYINT, Byte.class, UserDao.class);

    /**
     * 用户名
     */
    TableFile USER_NAME = new TableFile("user_name", "userName", "用户名", JdbcType.VARCHAR, String.class, UserDao.class);

    /**
     * 邮箱
     */
    TableFile EMAIL = new TableFile("email", "email", "邮箱", JdbcType.VARCHAR, String.class, UserDao.class);

    /**
     * 电话
     */
    TableFile PHONE_NUMBER = new TableFile("phone_number", "phoneNumber", "电话", JdbcType.VARCHAR, String.class, UserDao.class);

    /**
     * 性别0-男 1-女，2-保密
     */
    TableFile SEX = new TableFile("sex", "sex", "性别0-男 1-女，2-保密", JdbcType.TINYINT, Byte.class, UserDao.class);

    /**
     * 班级id
     */
    TableFile CLASS_ID = new TableFile("class_id", "classId", "班级id", JdbcType.BIGINT, Long.class, UserDao.class);

    /**
     * 班级名称
     */
    TableFile CLASS_NAME = new TableFile("class_name", "className", "班级名称", JdbcType.VARCHAR, String.class, UserDao.class);


    /**
     * user_id
     */
    TableFile USER_ID = new TableFile("user_id", "userId", "学号/工号", JdbcType.BIGINT, Long.class, UserDao.class);

    /**
     * 学校id
     */
    TableFile SCHOOL_ID = new TableFile("school_id", "schoolId", "学校id", JdbcType.BIGINT, Long.class, UserDao.class);

    /**
     * 学校名称
     */
    TableFile SCHOOL_NAME = new TableFile("school_name", "schoolName", "学校名称", JdbcType.VARCHAR, String.class, UserDao.class);

    /**
     * 真实姓名
     */
    TableFile REAL_NAME = new TableFile("real_name", "realName", "真实姓名", JdbcType.VARCHAR, String.class, UserDao.class);

    /**
     * 头像
     */
    TableFile AVATAR = new TableFile("avatar", "avatar", "头像", JdbcType.VARCHAR, String.class, UserDao.class);

    default List<ITableFile> allFields() {
        return Arrays.asList(ACCOUNT_NUMBER, PASSWORD, USER_TYPE, USER_NAME, EMAIL, PHONE_NUMBER,
                SEX, CLASS_ID, USER_ID, SCHOOL_ID, REAL_NAME, AVATAR);
    }

    static List<TableFile> getInsertFields() {
        return Arrays.asList(ACCOUNT_NUMBER, PASSWORD, USER_TYPE, USER_NAME, EMAIL, PHONE_NUMBER,
                SEX, CLASS_ID, CLASS_NAME, USER_ID, SCHOOL_ID, SCHOOL_NAME, REAL_NAME, AVATAR);
    }

    static List<TableFile> getSelectFields() {
        return Arrays.asList(ACCOUNT_NUMBER, USER_TYPE, USER_NAME, EMAIL, PHONE_NUMBER,
                SEX, CLASS_ID, CLASS_NAME, USER_ID, SCHOOL_ID, SCHOOL_NAME, REAL_NAME, AVATAR);
    }

    static List<TableFile> getStudentInfoFields() {
        return Arrays.asList(EMAIL, PHONE_NUMBER, SEX, CLASS_ID, USER_ID, SCHOOL_ID, REAL_NAME, AVATAR);
    }

    default String getTableName() {
        return "z_user_info";
    }

    /**
     * 校验密码
     *
     * @param userLogin
     * @return
     */
    int checkPassWord(@Param("user") UserLogin userLogin);

    /**
     * 统计班级学生数
     * @param schoolId 学校id
     * @param classId 班级id
     * @return 该班级学生数
     */
    int countStudent(@Param("schoolId") Long schoolId, @Param("classId") Long classId);

    /**
     * 条件 统计学生数
     * @param schoolId
     * @param classId
     * @param userId
     * @param realName
     * @return
     */
    int conditionCountStudent(@Param("schoolId") Long schoolId, @Param("classId")Long classId,
                              @Param("userId")Long userId, @Param("realName")String realName);
}
